﻿using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Temp.Model;

namespace Temp.View
{
    class NPCView
    {
        private List<Character> listNPC;
        private ContentManager Content; 

        private MouseState m;
        Point mouse;
        int curPlace;
        Texture2D[] pics;

        public NPCView(ContentManager content, List<Character> listNPC /*Planner planner*/)
        {
            this.listNPC = listNPC;
            this.Content = content;
            mouse = new Point();
            pics = new Texture2D[listNPC.Count];
        }
        public void LoadContent(ContentManager Content)
        {
            int i=0;
            foreach (Character ch in listNPC)
            {
                pics[i] = Content.Load<Texture2D>(ch.smallSrc);
                i++;
            }
        }

        public void Update(int curPlace)
        {
            this.curPlace = curPlace;
            handleMouse();
        }

        private void handleMouse()
        {
            m = Mouse.GetState();
            mouse.X = m.X;
            mouse.Y = m.Y;
            //intersectNPC();
        }

        //private void intersectNPC()
        //{
        //    foreach (Character c in listNPC)
        //    {
        //        Texture2D t = content.Load<Texture2D>(c.smallSrc);
        //        if (mouseBox.Intersects(new Rectangle(c.x, c.y, t.Width, t.Height)) && mouse.LeftButton == ButtonState.Pressed && mousePast.LeftButton == ButtonState.Released)
        //        {
        //            System.Diagnostics.Debug.WriteLine("clicked NPC");
        //            //planner.triggerEvent(c.id, "character");
        //        }
        //    }
        //    mousePast = mouse;
        //}

        public void Draw(SpriteBatch spriteBatch)
        {
            int i = 0;
            foreach (Character ch in listNPC)
            {
                if (curPlace == ch.idPlace)
                {
                    spriteBatch.Draw(pics[i], new Rectangle(ch.x, ch.y, 54, 87), Color.White);
                }
                i++;
            }
        }
    }
}
